<?
class model{
	private  $xhtml;
	private  $xsl;
	
	function addXhtml($xhtml){
		$this->xhtml = $xhtml;
	}
	
	function addXsl($xsl){
		$this->xsl = $xsl;
	}
	
	function transform(){
	
		$xsl = new XSLTProcessor();
		$xsl->importStyleSheet( DOMDocument::load( $this->xsl ) );
		return $xsl->transformToXML( DOMDocument::load( $this->xhtml ) );
	}
	
	function getData(){
		if (isset($this->xsl) &&  $this->xsl!="" && isset($this->xhtml) &&  $this->xhtml!=""){
			return $this->transform();
		}
		
		return false;
	}
	
	function sendSms($tm_login, $tm_password, $tm_to, $tm_mensaje){
				 
	
			 $host = 'opensms.movistar.es';
			 $service_uri = '/aplicacionpost/loginEnvio.jsp';
			 $vars="TM_ACTION=AUTHENTICATE&TM_LOGIN=".$tm_login."&TM_PASSWORD=".$tm_password."&to=".$tm_to."&message=".$tm_mensaje;
			 
			 # cabecera http HTTP
			 $header = "Host: $host\r\n";
			 $header .= "User-Agent: PHP Script\r\n";
			 $header .= "Encoding: utf-8\r\n";
			 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
			 $header .= "Content-Length: ".strlen($vars)."\r\n";
			 $header .= "Connection: close\r\n\r\n";
			 
			 $fp = pfsockopen($host, 443, $errno, $errstr);
			 
			 if (!$fp) {
			   echo "$errstr ($errno)\n";
			   echo $fp;
			 } else {
			   fputs($fp, "POST $service_uri HTTP/1.1\r\n");
			   fputs($fp, $header.$vars);
			   fwrite($fp, $out);
			   
		
			   # muestra la salida (opcional)
			   $str="";
			   while (!feof($fp)) {
					$str= fgets($fp, 128);
			   }
			   
			 fclose($fp);
			 return $str;
			}
	}
}
?>